package com.qiaoyanqing.ximalaya.discovermodule.discover_adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.qiaoyanqing.ximalaya.R;
import com.qiaoyanqing.ximalaya.discovermodule.discover_entity.Discover_ClassifyHead;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 27265 on 2016/12/7.
 */

public class DiscoverClassifyGrideAdapter extends BaseAdapter {
  private List<Discover_ClassifyHead> list;

    public DiscoverClassifyGrideAdapter(List<Discover_ClassifyHead> list, Context context) {
        this.list = list;
        this.context = context;
    }

    private Context context;

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if(view==null){
            view= LayoutInflater.from(context).inflate(R.layout.gride_item, viewGroup,false);
            holder=new ViewHolder();
            holder.iv= (ImageView) view.findViewById(R.id.image_gride);
            holder.tv= (TextView) view.findViewById(R.id.text_gride);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        Picasso.with(context).load(list.get(i).getCoverPath()).into(holder.iv);
        holder.tv.setText(list.get(i).getTitle());
        return view;
    }
    class ViewHolder{
           ImageView iv;
        TextView tv;
    }
}
